from django.conf import settings
from django.http import HttpResponse
from django.views.decorators.cache import cache_control
from Captcha.Visual.Tests import PseudoGimpy
                    
# TODO show "cookies is not enabled" image

@cache_control(no_cache=True)
def show(request):
    response = HttpResponse()
    response['Content-type'] = "image/png"
    g = PseudoGimpy()
    i = g.render((227, 50))
    i.save(response, "png")
    
    varName = settings.CAPTCHA_VARIABLE_NAME if hasattr(settings, 'CAPTCHA_VARIABLE_NAME') else 'captcha_code'
    request.session[varName] = hash(g.solutions[0]);
    return response    
